package com.jwj.testback.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.service.VendorExtension;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

@Configuration
@EnableSwagger2 //开启Swagger2
public class SwaggerConfig {
    @Bean
    public Docket docket() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                //enable是否启用swagger
//                .groupName("jwj");
                .select()
                // RequestHandlerSelectors,配置要扫描接口的方式
                // basePackage：指定要扫描的包
                // .any():扫描全部
                // none():都不扫描
                // .withClassAnnotation():扫描类上的注解，参数是一个注解的反射对象
                // .withMethodAnnotation():扫描方法上的注解
//                .apis(RequestHandlerSelectors.basePackage("com.jwj.controller")) 指定包位置
                .apis(RequestHandlerSelectors.any())
                //path().ant() 过滤扫描路径
                .paths(PathSelectors.any())
                .build();
    }

    //    配置Swagger信息=apiInfo
    private ApiInfo apiInfo() {
//        作者信息
        Contact contact = new Contact("jwj", "https://www.baidu.com/", "543027493@qq.com");
        return new ApiInfo("API文档",
                "作者",
                "v1.0",
                "https://www.baidu.com/",
                contact,
                "Apache 2.0",
                "http://www.apache.org/licenses/LICENSE-2.0",
                new ArrayList<VendorExtension>());
    }
}
